package com.six.controller;

import com.six.pojo.dto.LoginDto;
import com.six.result.Result;
import com.six.result.ResultUtils;
import com.six.service.AdminService;
import com.six.utils.WebUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin")
@Api(tags = "管理员管理的相关接口")
@Slf4j
@CrossOrigin
public class AdminController {

    @Autowired
    private AdminService adminService;
    @ApiOperation(value = "管理员的登录",notes = "管理员的登录")
    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public Result login(@RequestBody @Validated LoginDto loginDto, BindingResult bindingResult){

        if(bindingResult.hasErrors()){
            return WebUtils.getErrors(bindingResult);
        }
        String token = adminService.login(loginDto);
        return ResultUtils.buildSuccess(token);
    }
}
